<?php
namespace app\dc\controller;




use think\Controller;
use think\Db;

class Set  extends  Base
{
    public function email()
    {
      return $this->fetch();
    }
    public function website()
    {
        return $this->fetch();
    }
    public function password1()
    {
        if (request()->isAjax()) {
            $data = input('');


            if ($data['password']) {
                $data['password'] = cmf_password($data['password']);
            }
            $res = Db::name('admin')->where('password', $data['password'])->update($data);
            if ($res === false) {
                $this->success('操作失败');
            }
            $this->success('操作成功');

        }

        return $this->fetch();
    }




    public function password()
    {

        if (request()->isAjax()) {

            $data = input('');
            $oldpassword = trim($data['oldpassword']);
            $password = trim($data['password']);
            $repassword = trim($data['repassword']);
            if (!$oldpassword || !$password || !$repassword) {
                $this->error('数据异常');
            }

            if ($password != $repassword) {
                $this->error('两次密码不一致');
            }

            $pass = Db::name('admin')->where('id', $this->admin_id)->value('password');
            if ($pass != cmf_password($oldpassword)) {
                $this->error('密码错误');
            }
            Db::name('admin')->where('id', $this->admin_id)->update(['password' => cmf_password($password)]);
            $this->success('修改成功');


        }

        return $this->fetch();
    }
    public function info()
    {


        if (request()->isAjax()) {
            $data = input('');
            $res = Db::name('goods')->where('id', $data['id'])->update($data);
            if ($res === false) {
                $this->success('操作失败');
            }
            $this->success('操作成功');

        } else {

            $res = Db::name('admin')->find();
            $this->assign('item', $res);
            return $this->fetch();
        }

    }

}
